/*
	scheduler_functions.h

	contains headers for some common helper functions used within the scheduler

	Author: Aidan Goddard 25/7/13
*/
#ifndef SCHEDULER_FUNCTIONS_H_INCLUDED
#define SCHEDULER_FUNCTIONS_H_INCLUDED
#include"scheduler_tables.h"

// support functions
uint64_t	GetCPUTimeStamp(void);
uint64_t	CreatePID(uint32_t p_index);
uint64_t	CreateTID(uint64_t PID, uint32_t t_index);
uint32_t	GetPCBp(uint64_t PID);
uint32_t	GetPCBt(uint64_t TID);
uint32_t	GetTCBt(uint64_t TID);
uint32_t 	GetCPUID(void);
uint32_t 	GetCPUWithSmallestActiveQueue(void);

// scheduler only functions (these do not disable/enable interrupts, but require them to be disabled during operation)
uint32_t 	MoveThreadToCPU(int CPU, SCH_TLC* thread);
uint32_t	WakeThread(uint64_t TID, uint64_t message);
uint32_t	WakeThreadEx(uint64_t TID);
uint32_t	KillThread(uint64_t TID, uint64_t message);
void		PushTLC(SCH_TLC *tlc_to_push);
uint64_t	GetCurrentTID(void);

// application functions (these are expected to be called when interrupts are enabled)
uint64_t 	SleepMe(uint32_t sleep_time);
uint64_t 	WaitMe(void);
uint32_t	GetCPUUsage(int CPU);
uint32_t	GetCPUActiveThreads(int CPU);

#define WAKE_THREAD_SUCCESS 0
#define WAKE_THREAD_NOT_SLEEPING 1
#define WAKE_THREAD_NOT_IN_PROC 2

#define KILL_THREAD_SUCCESS 0
#define KILL_THREAD_NOT_ALIVE 1
#define KILL_THREAD_NOT_IN_PROC 2

#endif
